/////////////////////////////////////////////////////////////////////////////
// Name:        ide.h
// Author:      Nicolay Giraldo
// Created:     01/04/06
// Copyright:   Nicolay Giraldo
/////////////////////////////////////////////////////////////////////////////

#ifndef __ide_H__
#define __ide_H__

enum {
	ID_Splitter = 5000,
	ID_Frame,
	ID_FileNB,
	ID_FileWin,
	ID_ReplWin,
	ID_ReplResponse,
	ID_ReplPrompt,
	ID_ReplPPrompt,
	ID_ReplHistory,
	ID_ReplButton,
	ID_NEXT
};


class wxLogColorTextCtrl : public wxLog
{
public:
    wxLogColorTextCtrl(wxTextCtrl *pTextCtrl);

protected:
    // implement sink function
    virtual void DoLogString(const wxChar *szString, time_t t);

private:
    // the control we use
    wxTextCtrl *m_pTextCtrl;

    DECLARE_NO_COPY_CLASS(wxLogColorTextCtrl)
};


class textEditor : public wxTextCtrl 
{
	public:
	textEditor (wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTE_PROCESS_TAB|wxTE_MULTILINE|wxTE_RICH2|wxTE_READONLY);
	
	//! destructor
	~textEditor () {}
};

class reader;

class parens
{
	public:
	wxTextCtrl* parent;
	wxTextAttr& textattr;
	int start;
	int end;
	parens(wxTextCtrl* nparent, wxTextAttr& ntextattr) : parent(nparent), textattr(ntextattr), start(-1), end(-1) {}
	void clear() { start = -1; end = -1;}
	void setstart(int n) { start = n; }
	void setend(int n) { end = n;}
	void findmatch(int n);
	void clearhighlighting();
	void performhighlighting();
};


class promptEditor : public wxTextCtrl
{
	public:
	promptEditor (wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTE_PROCESS_TAB|wxTE_MULTILINE|wxTE_RICH2);
	
	//! destructor
	~promptEditor ();
	
	textEditor* response;
	reader* dareader;
	wxArrayString history;
	int hindex;
	
	long from;
	long to;
	parens prevparens;
	parens nextparens;
	parens outrparens;
	
	void OnKeyDown (wxKeyEvent &event);
	void OnKeyUp   (wxKeyEvent &event);
	void OnMouseDn (wxMouseEvent &event);
	void OnMouseUp (wxMouseEvent &event);
	void DoEval();
	void DoPrevText();
	void DoNextText();
};


extern wxTextAttr delimitersstyle;
extern wxTextAttr symbolsstyle   ;
extern wxTextAttr keywordstyle   ;
extern wxTextAttr stringsstyle   ;
extern wxTextAttr floatsstyle    ;
extern wxTextAttr fixnumsstyle   ;
extern wxTextAttr bignumsstyle   ;
extern wxTextAttr defaultstyle   ;
extern wxTextAttr errorstyle     ;
extern wxTextAttr hilightrstyle  ;
extern wxTextAttr hilightgstyle  ;
extern wxTextAttr hilightbstyle  ;

void init_text_attr(void);


class ide : public wxFrame
{
	public:
	ide(wxString);
	~ide();
	
	wxNotebook* filesbook;
	wxSplitterWindow* splitter;
	textEditor* filewin;
	wxSplitterWindow* replsplitter;
	textEditor* response;
	wxPanel* pprompt;
	wxGridSizer* sizer;
	promptEditor* prompt;
	wxSpinButton* history;
	wxButton* send;
//	~ide();
	wxToolBar* datoolbar;
	wxStatusBar* dastatusbar;
	
	void OnEval(wxCommandEvent &event);
	void OnSpinUp(wxSpinEvent &event);
	void OnSpinDn(wxSpinEvent &event);
};


void completeparens(wxString* s_expr);


#endif
